<template>
  <div>
    <el-dialog
      v-dialogDrag
      ref="dialog"
      :close-on-click-modal="false"
      :visible.sync="editDialog"
      :before-close="cancel"
      :append-to-body="true"
      title="编辑短信模板"
      width="30%"
      @open="init"
    >
      <el-form
        ref="Form"
        :inline="true"
        :model="smsInfo"
        :rules="rules"
        label-width="95px">
        <el-row>
          <el-col :span="24">
            <el-form-item>
              <span>【江铃汽车】尊敬的客户：感谢您关注江铃新能源汽车</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item style="width:100%;" prop="noticeText">
              <el-input v-model="smsInfo.noticeText" clearable/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item>
              <span>更多信息请访问江铃汽车新能源商城：</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item style="width:100%;" prop="noticeAddress">
              <el-input v-model="smsInfo.noticeAddress" clearable/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>

      <div slot="footer" class="dialog-footer" style="text-align:center;">
        <el-button type="text">
          <i class="el-icon-search magnifier" />
        </el-button>
        <el-button type="primary" @click="confirm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import rSelect from '@/components/Select/Select'
import BaseTable from '@/components/BaseTable'
import filtercode from '@/components/Checkbox/filtercode'
import { sendSmg } from '@/api/vehicle/custBiz.js'
import formMixins from '@/mixins/formMixins'
import moment from 'moment'
// import _ from 'lodash'

export default {
  name: 'SmsDialog',
  components: {
    BaseTable,
    rSelect,
    filtercode,
    moment
  },

  mixins: [formMixins],
  props: {
    editDialog: {
      type: Boolean,
      default: false
    },
    multipleSelection: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      rules: {
        noticeAddress: [{ trigger: 'blur', required: true, message: '链接地址不能为空' }],
        noticeText: [{ max: 70, message: '最多70个字符', trigger: 'blur' }]
      },
      smsInfo: {
        noticeText: '',
        noticeAddress: process.env.MALL_H5_URL
      }
    }
  },

  mounted() {
  },
  methods: {
    init() {
    },

    confirm() {
      this.$refs['Form'].validate(valid => {
        if (valid) {
          if (this.multipleSelection.length !== 0) {
            let ids = ''
            this.multipleSelection.forEach(item => {
              if (ids === '') {
                ids = item['user_id']
              } else {
                ids = ids + ',' + item['user_id']
              }
            })
            const param = {
              ids: ids,
              type: 'user',
              noticeAddress: this.smsInfo.noticeAddress,
              noticeText: this.smsInfo.noticeText
            }
            sendSmg(param).then(() => {
              this.$message({
                type: 'success',
                message: '发送短息成功!'
              })
              this.cancel()
            }).catch(err => {
            })
          } else {
            this.$message({
              type: 'warning',
              message: '请选择表格数据'
            })
          }
        }
      })
    },

    cancel() {
      this.$emit('smsClose')
    }
  }
}
</script>

<style lang="scss" scoped>
::v-deep {
  .el-form-item__content {
    width: 100% !important;
  }
}
</style>
